﻿<cfsilent>
	<cfscript>

		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");

		taskProp = getProperty("serviceFactory").getBean("taskPropertyAdvice");
		
		response = structNew();
		structInsert(response, "success", false, true);
		
		termId = event.getArg("TID");
		courseId = event.getArg("CID");

		arrangeMode = event.getArg("MODE");
		
		transaction {
			
			/* 载入课程排课任务 */
			sql = "	SELECT
						t.task_id,t.task_type
					FROM
						t_task_arrange t
					WHERE
						t.cid = :courseId 
						AND
						t.term_id = :termId ";

			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "courseId", value = courseId, cfsqltype = "cf_sql_varchar");
			queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
			rs_taskArrange = queryObj.execute(sql = sql).getResult();

			for(a = 1; a lte rs_taskArrange.recordCount; a++){
				
				taskId = rs_taskArrange['task_id'][a];
				taskType = rs_taskArrange['task_type'][a];
				
				/* 载入教学任务 */
				
				/* 更新排课模式 */
				
				switch(taskType){
					case 'C':
						sql = "	UPDATE
									t_common_task t
								SET
									t.task_mode = :taskMode 
								WHERE
									t.tsk_id = :taskId ";
						break;
					case 'P':
						sql = "	UPDATE
									t_task t
								SET
									t.task_mode = :taskMode 
								WHERE
									t.tsk_id = :taskId ";
						break;
					case 'R':
						sql = "	UPDATE
									t_reopen_task t
								SET
									t.task_mode = :taskMode 
								WHERE
									t.tsk_id = :taskId ";
						break;
					case 'T':
						sql = "	UPDATE
									t_sport_task t
								SET
									t.task_mode = :taskMode 
								WHERE
									t.tsk_id = :taskId ";
						break;
				}
				
				queryObj = new Query(datasource = application.dnsMaster);
				queryObj.addParam(name = "taskId", value = taskId, cfsqltype = "cf_sql_varchar");
				queryObj.addParam(name = "taskMode", value = arrangeMode, cfsqltype = "cf_sql_char");
				queryObj.execute(sql = sql);
				
			}
			
			structInsert(response, "success", true, true);
		
		}
		
	
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>